Skip to content

feat: add AsNativeArray() read‑only accessor to NetworkList<T> #3567

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Aug 5, 2025

Conversation

EmandM
Copy link
Collaborator

@EmandM EmandM commented Jul 30, 2025

Continues: #3562 from @harayuu9

This PR exposes the contents of a NetworkList<T> as a read‑only NativeArray<T>.
It addresses the recurring need to interoperate efficiently with Burst‑compiled or IJob‑based code without paying the cost of element‑wise copies or allocations.
The accessor simply forwards m_List.AsReadOnly(), preserving zero‑allocation semantics while respecting NativeArray’s lifetime constraints (call‑site must guarantee the list is not mutated or disposed).
No behavioural changes are introduced—only a pure additive surface‑area expansion.

Changelog

  • Added: NetworkList<T>.AsNativeArray() to return the list contents as a NativeArray<T>.ReadOnly.

Testing and Documentation

  • No tests have been added.
  • Includes documentation for the newly added public API function.

Backport

This adds new API surface area and so no backport is required.

@EmandM EmandM requested a review from a team as a code owner July 30, 2025 20:10
@EmandM EmandM added the port:1.x-needed This issue needs to be ported to 1.X branch label Jul 30, 2025
@EmandM EmandM changed the title Feat/add networklist as native array feat: add AsNativeArray() read‑only accessor to NetworkList<T> Jul 30, 2025
@EmandM EmandM removed the port:1.x-needed This issue needs to be ported to 1.X branch label Jul 30, 2025
@NoelStephensUnity
Copy link
Collaborator

@harayuu9
Thank you for your contribution.
As a side note, you can also just do this to accomplish the same thing:

    private NetworkVariable<NativeList<int>> m_MyList = new NetworkVariable<NativeList<int>>();
    public NativeArray<int>.ReadOnly MyList => m_MyList.Value.AsReadOnly();

Copy link
Collaborator

@NoelStephensUnity NoelStephensUnity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:godmode:

@EmandM EmandM enabled auto-merge (squash) August 1, 2025 18:34
@EmandM EmandM merged commit f4b6cd4 into develop-2.0.0 Aug 5, 2025
25 checks passed
@EmandM EmandM deleted the feat/add_networklist_asNativeArray branch August 5, 2025 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants